package com.example.airport;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ClipData;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.example.airport.data.Directionary;
import com.example.airport.data.Suggestion;
import com.example.airport.net.G;
import com.example.airport.net.datarequest.Http;
import com.example.airport.net.datarequest.IBack;
import com.example.airport.parent.FatherActivity;
import com.example.airport.utils.DictUtil;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;


import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import okhttp3.ResponseBody;
import retrofit2.http.QueryMap;

public class SplashActivity extends FatherActivity implements  IBack {

    private Http userserverData=new Http(G.DICTIONARY_URL,"getAll",this,0);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        userserverData.httpGet();
        Intent intent=new Intent();
        intent.setClass(SplashActivity.this,MainActivity.class);
        startActivity(intent);
        finish();

    }


    /***
     * 获取字典
     * @param index
     * @param body
     * @throws IOException
     */
    @Override
    public void success(int index, ResponseBody body) throws IOException {

        String json = new String(body.bytes());
        Gson gson = new Gson();
        Directionary directionary = gson.fromJson(json, Directionary.class);
        ArrayList<Directionary.Data> list=directionary.getData();

        Map<String, String> _directionary = new HashMap<>();
        for (Directionary.Data item:list)
        {
            _directionary.put(item.getKey(),item.getValue());
        }
        DictUtil.setDictionary(_directionary);

    }

    @Override
    public void failure(int index, String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
}